#!/usr/local/python27/bin/python2.7
import os, getopt, sys
import zipfile
import traceback

def usage():
   print 'Usage: ', sys.argv[0], '-f inputfile -o output_dir'

try:
    opts, args = getopt.getopt(sys.argv[1:], '-i:o:h', ['help'])
    if len(opts) != 2:
        usage()
    else:

        for opt,arg in opts:
            if opt in ('-h', '--help'):
                usage()
                break
            elif opt in ('-i', '--input'):
                inputFile = arg
            elif opt in ('-o', '--output'):
                outputFile = arg
        else:
            if (not os.path.exists(inputFile)) or (not os.path.isdir(outputFile)):
                print 'input:%s or output:%s not exists' % (inputFile, outputFile)
                sys.exit(3)
            zipFile = zipfile.ZipFile(inputFile)
            for file in zipFile.namelist():
                zipFile.extract(file, outputFile)
            zipFile.close()
except:
    traceback.print_exc()
    sys.exit(2)